package com.jcl.recruit.resume.mapper;

import com.jcl.recruit.resume.model.ResumeOrig;
import com.jcl.recruit.resume.provider.ResumeOrigSqlProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author 刘明新
 * @date 2018/9/3 下午4:09
 */
public interface ResumeOrigMapper {

    @Select({
            "select * from resume_orig where status = 0 and source = #{source} order by id"
    })
    List<ResumeOrig> selectResumeOrigsBySource(@Param("source") String source);

    @Update({
            "<script>",
            "<foreach collection='list' item='entity' index='index' separator=';'>",
            "update resume_orig set status = 1 where id = #{entity}",
            "</foreach>",
            "</script>"
    })
    int batchUpdate(@Param("list") List<Integer> list);

    @Select({
            "select DATE_FORMAT(createtime,'%Y-%m-%d') as '日期',source as '来源',count(*) as '数量' from resume_orig group by",
            "DATE_FORMAT(createtime,'%Y-%m-%d'),source order by DATE_FORMAT(createtime,'%Y-%m-%d'),source",
    })
    List<Map<String,String>> selectPrimarykeyByDatesAndSources();

    @InsertProvider(type= ResumeOrigSqlProvider.class, method="insertSelective")
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insertSelective(ResumeOrig record);
}
